package cn.org.timespace.easyframe.util.sms.telecom;



import java.io.UnsupportedEncodingException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.huawei.insa2.comm.smgp.message.*;
import com.huawei.insa2.util.*;
import com.huawei.smproxy.*;

public class MySMGPSMProxy extends SMGPSMProxy {

	private final static Log log = LogFactory.getLog(MySMGPSMProxy.class);
	
	private DeliverMsg deliver=null;
	public MySMGPSMProxy(DeliverMsg deliver,Args args) throws Exception {
		super(args);
		this.deliver=deliver;
	}
	
	

	/**
	 * ��������·�����Ϣ�Ĵ��?
	 * 
	 * @param msg
	 *            �յ�����Ϣ
	 * @return ���ص���Ӧ��Ϣ��
	 */
	@Override
	public SMGPMessage onDeliver(SMGPDeliverMessage msg) {
		// ����յ�����Ϣ�����·���Ϣ�Ĵ������
		//����Ƿ�Ϊ״̬����
		String encode = "ISO8859-1";
		if (msg.getMsgFormat() == 8)
			encode = "iso-10646-ucs-2";
		if (msg.getMsgFormat() == 15)
			encode = "GB2312";
		
		if(msg.getIsReport()==1)
		{
			byte[] msgs =msg.getMsgContent();
			try {
				try {
					String contentStr = new String(msgs, encode);
					log.info("�յ�״̬����:" + contentStr);
				} catch (UnsupportedEncodingException e) {
					log.error(e.getMessage());
				}
			} catch (Exception e) {
				log.error(e.getMessage());
			}
			
		}else{
			byte[] msgs =msg.getMsgContent();
			try {
				String contentStr = new String(msgs, encode);
				log.info("�ͻ�������Ϣ:"+contentStr);
			} catch (UnsupportedEncodingException e) {
				log.error(e.getMessage());
			}
			// �����û��������
			deliver.ProcessRecvDeliverMsg(msg);
			
			
		}
		return super.onDeliver(msg);
	}

	/**
	 * l����ֹ�Ĵ��?��APIʹ����ʵ�� SMCl����ֹ����Ҫִ�ж���Ľӿ�
	 * @throws CloneNotSupportedException 
	 */
	public void OnTerminate() throws CloneNotSupportedException {
		deliver.Terminate();
	}
}
